﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HR.Appointments.Service;

public partial class Company : UserPage
{
    #region Events
    protected void Page_Load(object sender, EventArgs e)
    {
        //_imgConfirm.Visible = IsLoggedIn;
        //if (!IsPostBack)
        //{
        ListCompanies();
        //}
    }

    protected void Repeater1_ItemCommand(object sender, RepeaterCommandEventArgs e)
    {
        //TODO: Mark user as logged of but do not delete the cookie!
        //HACK: Create a dummy user that will not be logged on.
        Logon("!#$%&%", ")765456%$#(((");

        SetCompanyIdToCookie(e.CommandArgument.ToString());
        Server.Transfer("~/CustomerBooking.aspx",true);
    }
    #endregion

    #region Link Transefer
    protected void _lbtnDisplayOrders_Click(object sender, EventArgs e)
	{
		Server.Transfer("~/DisplayOrders.aspx",true);
	}
	protected void _lbtnNewEntryCompany_Click(object sender, EventArgs e)
	{
		Server.Transfer("~/NewEntryCompany.aspx",true);
	}
	protected void _lbtnLogin_Click(object sender, EventArgs e)
	{
		Server.Transfer("~/Login.aspx",true);
	}
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        ListCompanies();
    }
	protected void _ibmHomePage_Click(object sender, ImageClickEventArgs e)
	{
		//if (!IsPostBack || (e.X != 0 && e.Y != 0))
		//{
            Response.Redirect("~/Company.aspx");        
       // }

    }
    #endregion

    #region Private List Methods
    private void ListCompanies()
    {
        if (!string.IsNullOrEmpty(txtSearch.Text.Trim()))
        {
            _repeater.DataSource = Facade.SearchCompaniesByName(txtSearch.Text);
        }
        else
        {
            _repeater.DataSource = Facade.AvailableCompanies();
        }
        _repeater.DataBind();
    }
    #endregion
	protected void _lbtnCompany_Click(object sender, EventArgs e)
	{
		Response.Redirect("~/Company.aspx");
	}
}
